package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysNotice;
import com.microcdyUser.service.SysNoticeService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysNotice")
@CrossOrigin
public class SysNoticeController {

    @Autowired
    private SysNoticeService sysNoticeService;

    /***
     * SysNotice分页条件搜索实现
     * @param sysNotice
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysNotice sysNotice, @PathVariable  int page, @PathVariable  int size){
        //调用SysNoticeService实现分页条件查询SysNotice
        PageInfo<SysNotice> pageInfo = sysNoticeService.findPage(sysNotice, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysNotice分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysNoticeService实现分页查询SysNotice
        PageInfo<SysNotice> pageInfo = sysNoticeService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysNotice
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysNotice>> findList(@RequestBody(required = false)  SysNotice sysNotice){
        //调用SysNoticeService实现条件查询SysNotice
        List<SysNotice> list = sysNoticeService.findList(sysNotice);
        return new Result<List<SysNotice>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用SysNoticeService实现根据主键删除
        sysNoticeService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysNotice数据
     * @param sysNotice
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysNotice sysNotice,@PathVariable Integer id){
        //设置主键值
        sysNotice.setNoticeId(id);
        //调用SysNoticeService实现修改SysNotice
        sysNoticeService.update(sysNotice);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysNotice数据
     * @param sysNotice
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysNotice sysNotice){
        //调用SysNoticeService实现添加SysNotice
        sysNoticeService.add(sysNotice);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysNotice数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysNotice> findById(@PathVariable Integer id){
        //调用SysNoticeService实现根据主键查询SysNotice
        SysNotice sysNotice = sysNoticeService.findById(id);
        return new Result<SysNotice>(true,StatusCode.OK,"查询成功",sysNotice);
    }

    /***
     * 查询SysNotice全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysNotice>> findAll(){
        //调用SysNoticeService实现查询所有SysNotice
        List<SysNotice> list = sysNoticeService.findAll();
        return new Result<List<SysNotice>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
